package com.runssnail.juhe.api.request.mobile;

import com.runssnail.juhe.api.constants.Constants;
import com.runssnail.juhe.api.internal.utils.MD5Util;
import com.runssnail.juhe.api.request.GetRequest;
import com.runssnail.juhe.api.response.mobile.MobileRechargeResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * 手机话费充值
 *
 * Created by zhengwei on 16/4/14.
 */
public class MobileRechargeRequest extends GetRequest<MobileRechargeResponse> {

    /**
     * 手机号
     */
    private String phone;

    /**
     * 金额 10、20、30、50、100、300
     */
    private int amount;

    /**
     * 商家订单号，8-32位字母数字组合
     */
    private String orderId;

    /**
     * open id
     */
    private String openId;

    private String appKey;

    @Override
    public String getApiUrl() {
        return "http://op.juhe.cn/ofpay/mobile/onlineorder";
    }

    @Override
    public Map<String, Object> getParams() {
//        phoneno	string	是	手机号码
//        cardnum	string	是	充值金额,目前可选：10、20、30、50、100、300
//        orderid	string	是	商家订单号，8-32位字母数字组合
//        key	string	是	应用APPKEY(应用详细页查询)
//                sign	string	是	校验值，md5(OpenID+key+phoneno+cardnum+orderid)，OpenID在个人中心查询

        Map<String, Object> params = new HashMap<>();
        params.put("orderid", this.orderId);
        params.put("phoneno", this.phone);
        params.put("cardnum", this.amount);

        String signStr = this.openId + this.appKey + this.phone + this.amount + this.orderId;

        String sign = MD5Util.MD5Encode(signStr, Constants.DEFAULT_ENCODING).toLowerCase();

        params.put("sign", sign);

        return params;
    }

    @Override
    public Class<MobileRechargeResponse> getResponseClass() {
        return MobileRechargeResponse.class;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }
}
